package com.wbw.ssb.mbg.mapper;

import static com.wbw.ssb.mbg.mapper.GranaryDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.*;

import com.wbw.ssb.mbg.entity.Granary;
import java.util.List;
import java.util.Optional;
import javax.annotation.Generated;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;

@Mapper
public interface GranaryMapper {
    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    BasicColumn[] selectList = BasicColumn.columnList(id, number, name, status, longitude, latitude, enable);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    long count(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @DeleteProvider(type=SqlProviderAdapter.class, method="delete")
    int delete(DeleteStatementProvider deleteStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @InsertProvider(type=SqlProviderAdapter.class, method="insert")
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="record.id", before=false, resultType=Long.class)
    int insert(InsertStatementProvider<Granary> insertStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @ResultMap("GranaryResult")
    Optional<Granary> selectOne(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @Results(id="GranaryResult", value = {
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="number", property="number", jdbcType=JdbcType.BIGINT),
        @Result(column="name", property="name", jdbcType=JdbcType.VARCHAR),
        @Result(column="status", property="status", jdbcType=JdbcType.BIT),
        @Result(column="longitude", property="longitude", jdbcType=JdbcType.DOUBLE),
        @Result(column="latitude", property="latitude", jdbcType=JdbcType.DOUBLE),
        @Result(column="enable", property="enable", jdbcType=JdbcType.BIT)
    })
    List<Granary> selectMany(SelectStatementProvider selectStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    @UpdateProvider(type=SqlProviderAdapter.class, method="update")
    int update(UpdateStatementProvider updateStatement);

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default long count(CountDSLCompleter completer) {
        return MyBatis3Utils.countFrom(this::count, granary, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int delete(DeleteDSLCompleter completer) {
        return MyBatis3Utils.deleteFrom(this::delete, granary, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int deleteByPrimaryKey(Long id_) {
        return delete(c -> 
            c.where(id, isEqualTo(id_))
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int insert(Granary record) {
        return MyBatis3Utils.insert(this::insert, record, granary, c ->
            c.map(number).toProperty("number")
            .map(name).toProperty("name")
            .map(status).toProperty("status")
            .map(longitude).toProperty("longitude")
            .map(latitude).toProperty("latitude")
            .map(enable).toProperty("enable")
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int insertSelective(Granary record) {
        return MyBatis3Utils.insert(this::insert, record, granary, c ->
            c.map(number).toPropertyWhenPresent("number", record::getNumber)
            .map(name).toPropertyWhenPresent("name", record::getName)
            .map(status).toPropertyWhenPresent("status", record::getStatus)
            .map(longitude).toPropertyWhenPresent("longitude", record::getLongitude)
            .map(latitude).toPropertyWhenPresent("latitude", record::getLatitude)
            .map(enable).toPropertyWhenPresent("enable", record::getEnable)
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default Optional<Granary> selectOne(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectOne(this::selectOne, selectList, granary, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default List<Granary> select(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectList(this::selectMany, selectList, granary, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default List<Granary> selectDistinct(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectDistinct(this::selectMany, selectList, granary, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default Optional<Granary> selectByPrimaryKey(Long id_) {
        return selectOne(c ->
            c.where(id, isEqualTo(id_))
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int update(UpdateDSLCompleter completer) {
        return MyBatis3Utils.update(this::update, granary, completer);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    static UpdateDSL<UpdateModel> updateAllColumns(Granary record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(number).equalTo(record::getNumber)
                .set(name).equalTo(record::getName)
                .set(status).equalTo(record::getStatus)
                .set(longitude).equalTo(record::getLongitude)
                .set(latitude).equalTo(record::getLatitude)
                .set(enable).equalTo(record::getEnable);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    static UpdateDSL<UpdateModel> updateSelectiveColumns(Granary record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(number).equalToWhenPresent(record::getNumber)
                .set(name).equalToWhenPresent(record::getName)
                .set(status).equalToWhenPresent(record::getStatus)
                .set(longitude).equalToWhenPresent(record::getLongitude)
                .set(latitude).equalToWhenPresent(record::getLatitude)
                .set(enable).equalToWhenPresent(record::getEnable);
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int updateByPrimaryKey(Granary record) {
        return update(c ->
            c.set(number).equalTo(record::getNumber)
            .set(name).equalTo(record::getName)
            .set(status).equalTo(record::getStatus)
            .set(longitude).equalTo(record::getLongitude)
            .set(latitude).equalTo(record::getLatitude)
            .set(enable).equalTo(record::getEnable)
            .where(id, isEqualTo(record::getId))
        );
    }

    @Generated("org.mybatis.generator.api.MyBatisGenerator")
    default int updateByPrimaryKeySelective(Granary record) {
        return update(c ->
            c.set(number).equalToWhenPresent(record::getNumber)
            .set(name).equalToWhenPresent(record::getName)
            .set(status).equalToWhenPresent(record::getStatus)
            .set(longitude).equalToWhenPresent(record::getLongitude)
            .set(latitude).equalToWhenPresent(record::getLatitude)
            .set(enable).equalToWhenPresent(record::getEnable)
            .where(id, isEqualTo(record::getId))
        );
    }
}